package printParse.excel.jxlExcel;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Date;

import jxl.CellReferenceHelper;
import jxl.Workbook;
import jxl.write.DateFormats;
import jxl.write.DateTime;
import jxl.write.Formula;
import jxl.write.Label;
import jxl.write.Number;
import jxl.write.WritableCellFormat;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;

public class DataTypeExcelWrite {
	public void createExcel(OutputStream os) throws IOException,
			RowsExceededException, WriteException {

		// 床架工作簿
		WritableWorkbook workbook = Workbook.createWorkbook(os);
		// 创建新的一页
		WritableSheet sheet = workbook.createSheet("first sheet", 0);

		// 创建内容
		Label format = new Label(0, 0, "数据格式");
		sheet.addCell(format);
		Label floats = new Label(1, 0, "浮点型");
		sheet.addCell(floats);
		Label floats_2 = new Label(6, 0, "浮点型2");
		sheet.addCell(floats_2);
		Label integer = new Label(2, 0, "整形");
		sheet.addCell(integer);
		Label booleans = new Label(3, 0, "布尔型");
		sheet.addCell(booleans);
		Label date = new Label(4, 0, "日期类型");
		sheet.addCell(date);
		Label formula = new Label(5, 0, "formula");
		sheet.addCell(formula);

		Label example = new Label(0, 1, "数据示例");
		sheet.addCell(example);
		// 浮点数据
		Number number = new Number(1, 1, 3);
		sheet.addCell(number);
		// 浮点数据
		Number number2 = new Number(6, 1, 7);
		sheet.addCell(number2);
		// 整形数据
		Number ints = new Number(2, 1, 111);
		sheet.addCell(ints);
		// 布尔型
		// Boolean bools = new Boolean(3,1,true);
		// sheet.addCell(bools);
		Number number3 = new Number(3, 1, 7);
		sheet.addCell(number3);
		// 日期类型
		Date d = new Date();
		WritableCellFormat f = new WritableCellFormat(DateFormats.FORMAT1);
		DateTime dt = new DateTime(4, 1, d, f);
		sheet.addCell(dt);
		// formula
		Formula ff = new Formula(5, 1, "SUM(B2:D2)");
		sheet.addCell(ff);

		// 将北荣写入输出流，并且关闭流
		workbook.write();
		workbook.close();
		os.close();

	}

	public static void main(String[] args) throws RowsExceededException,
			WriteException, FileNotFoundException, IOException {

		DataTypeExcelWrite dtew = new DataTypeExcelWrite();
		dtew.createExcel(new FileOutputStream(new File("D://haha.xls")));
		System.out.println("--SUCCESS--");
		System.out.println(CellReferenceHelper.getCellReference(11, 11));

	}

}
